<?php
ob_start(); 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Manage_Scoring extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		
		$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
		$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
		$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
		$this->output->set_header('Pragma: no-cache');
		$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		
		$this->allowed =array('admin', 'panelist');
		
		#load all database and required models
		$this->load->database();
		$this->load->model('common_model');
		$this->load->model('scoring_model');
	    $this->load->model('admin_model');
		$this->load->model('event_model');
		$this->load->model('user_model');
		
		$this->data = array();
		$this->data['admin_value'] = $this->session->all_userdata();
		if($this->data['admin_value']['admin_type'] == 'Web Admin' || $this->data['admin_value']['admin_type'] == 'Sub Admin')
		{
			$this->admin = 'admin';
		}
		else {
			$this->admin = 'panelist';
		}
	}
	
	public function createScore($value=""){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if($this->input->get('award_id') && preg_match("/^[0-9]+$/",$this->input->get('award_id'))){
				$award_id = $this->input->get('award_id');
			}
			else {
				header('Location: '.BASE_URL.'/'.$admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			if($this->input->post('user_application_applicant_id')){
				$this->data['post_value'] = $this->input->post();
				$val = $this->scoring_model->addScoring($this->data['post_value']);
				exit();
			}
			$this->data['rows'] = $this->scoring_model->getAllApplicant($award_id);
			$this->data['all_criteria'] = $this->event_model->getCriteriaById($award_id);
			$this->data['event_detail'] = $this->user_model->getFormData($award_id);
			//var_dump($this->data['event_detail']);die();
		
			$this->load->view('admin/scoring/admin_score',$this->data);
		
		//var_dump($this->data['rows2']); die();
		/*if($this->data['rows1'][0]['admin_review_applicant_id'] != $this->input->post('hidden1') AND $this->data['rows1'][0]['admin_review_award_id'] != $this->input->post('hidden2') AND $this->data['rows2'][0]['award_event_id'] != $this->input->post('hidden3'))
			{*/
				/*if($this->input->post('citation_including_self')) {
						$this->data['post_value'] = $this->input->post();
						$val = $this->scoring_model->addScoring($this->data['post_value']);
							if($val > 0)
							{
								$this->session->set_userdata('score_success', 'Score added succefully');
								header('Location: '.BASE_URL.'/'.$admin.'/admin_score');
								redirect(BASE_URL.'/'.$this->admin.'/admin_score');
								exit();
							}
							else
							{
								$this->data['error']='Problem in creating Event';
								$this->load->view('admin/scoring/admin_score',$this->data);
							}
				}*/
						
					/*{
						$this->data['post_value'] = $this->input->post();	
						$this->data['error'] = validation_errors();
						
					}*/
					
				
			/*else
			{
				var_dump('here'); die();*/
			//	$this->load->view('admin/scoring/admin_score',$this->data);	
			//}
	/*	}
		else{*/
		//	$this->data['post_value'] = $this->input->post();
		//	$val = $this->scoring_model->updateScore($this->data['post_value']);//}
		//var_dump($this->data); die();
			
	//	}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function admin_scoresecond(){
	$this->session->set_userdata('xynnn',$_POST);
    $journals_avcitationperpaper = $_POST;
    $this->scoring_model->addSecondScore($journals_avcitationperpaper);
}
	
	public function panalist_scoring(){
		if($this->input->get('award_id')){
			$award_id = $this->input->get('award_id');
		}
		$data['admin_score'] = $this->scoring_model->get_adminScore($award_id);
		$data['applicant_list'] = $this->scoring_model->get_applicant($award_id);
		$data['result'] = $this->scoring_model->get_score_panelist($award_id);
		$this->load->view('admin/scoring/panelist_scoring',$data);
	}
	
	public function panelist_score(){
		$data= array();
		$data['award_id'] = htmlspecialchars(strip_tags($this->input->get_post('award', TRUE),ENT_QUOTES));
		$data['event_id'] = htmlspecialchars(strip_tags($this->input->get_post('event', TRUE),ENT_QUOTES));
		$data['applicant_id'] = htmlspecialchars(strip_tags($this->input->get_post('applicant', TRUE),ENT_QUOTES));
		$data['score'] =  htmlspecialchars(strip_tags($this->input->get_post('score', TRUE),ENT_QUOTES));
		$data['ws_score'] = htmlspecialchars(strip_tags($this->input->get_post('ws_score', TRUE),ENT_QUOTES));
		$data['type'] = htmlspecialchars(strip_tags($this->input->get_post('type', TRUE),ENT_QUOTES));
		if($this->scoring_model->panelist_scoring($data)){
			return true;
		}
		else {
			return false;
		}
	}
	
	public function panelist_score_excel(){
		$data = array();
		$data['result'] = $this->scoring_model->panelist_score_excel();
		$i = $data['result'][0]->panelist_review_event_id; 
		$data['result1'] = $this->scoring_model->fetch_eventname($i);
		$j = $data['result'][0]->panelist_review_award_id;
		$data['result2'] = $this->scoring_model->fetch_eventname($i);
		
	}
	
}